


function AddFavorite(sURL, sTitle)
{
    try
    {
        window.external.addFavorite(sURL, sTitle);
    }
    catch (e)
    {
        try
        {
            window.sidebar.addPanel(sTitle, sURL, "");
        }
        catch (e)
        {
            alert("加入收藏失败，请使用Ctrl+D进行添加");
        }
    }
}

function SetHome(obj,vrl){
        try{
                obj.style.behavior='url(#default#homepage)';obj.setHomePage(vrl);
        }
        catch(e){
                if(window.netscape) {
                        try {
                                netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");  
                        }  
                        catch (e)  { 
                                alert("此操作被浏览器拒绝！\n请在浏览器地址栏输入“about:config”并回车\n然后将[signed.applets.codebase_principal_support]设置为'true'");  
                        }
                        var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
                        prefs.setCharPref('browser.startup.homepage',vrl);
                 }
        }
}



/// reset the menu itemstatus.
/*$("topMenu").addEvent('mouseout', function(){
	this.getElements('div').each(
		function(){			
			rollmove(this, 0);
		}
	);
});*/

/// change the style of div
function rollmove(obj, direct){

	name = obj.className.replace(/_act/g,"");;

	if (direct == 1){
	  obj.className = name+"_act";
	}else{
	  obj.className = name;
	}
}

function wimg(imguri){
	document.write("<img src='"+ imguri + "' />");
}

/// 扩展js，自定义样式表单元素
//// add by liuran 2009-4-25 change radio and checkbox style

var labels = null;
var inputs = null;
var textareas = null;
var selects = null;
var ua = navigator.userAgent.toLowerCase();
var isOpera = (ua.indexOf('opera') != -1);
var isIE = (document.all && window.ActiveXObject && !window.opera) ? true : false;

function dom(id)
{
	return document.getElementById(id);
}


function getElementPos(el) {

	if(el.parentNode === null || el.style.display == 'none') 
	{
		return false;
	}
 
	var parent = null;
	var pos = [];
	var box;
 
	if(el.getBoundingClientRect)	//IE
	{
		box = el.getBoundingClientRect();
		var scrollTop = Math.max(document.documentElement.scrollTop, document.body.scrollTop);
		var scrollLeft = Math.max(document.documentElement.scrollLeft, document.body.scrollLeft);
 
		return {x:box.left + scrollLeft, y:box.top + scrollTop};
	}
	else if(document.getBoxObjectFor)	// gecko
	{
		box = document.getBoxObjectFor(el);
		   
		var borderLeft = (el.style.borderLeftWidth)?parseInt(el.style.borderLeftWidth):0;
		var borderTop = (el.style.borderTopWidth)?parseInt(el.style.borderTopWidth):0;
 
		pos = [box.x - borderLeft, box.y - borderTop];
	}
	else	// safari & opera
	{
		pos = [el.offsetLeft, el.offsetTop];
		parent = el.offsetParent;
		if (parent != el) {
			while (parent) {
				pos[0] += parent.offsetLeft;
				pos[1] += parent.offsetTop;
				parent = parent.offsetParent;
			}
		}
		if (ua.indexOf('opera') != -1 
			|| ( ua.indexOf('safari') != -1 && el.style.position == 'absolute' )) 
		{
				pos[0] -= document.body.offsetLeft;
				pos[1] -= document.body.offsetTop;
		} 
	}
		
	if (el.parentNode) { parent = el.parentNode; }
	else { parent = null; }
  
	while (parent && parent.tagName != 'BODY' && parent.tagName != 'HTML') 
	{ // account for any scrolled ancestors
		pos[0] -= parent.scrollLeft;
		pos[1] -= parent.scrollTop;
  
		if (parent.parentNode) { parent = parent.parentNode; } 
		else { parent = null; }
	}
	return {x:pos[0], y:pos[1]};
}


function stopBubbling (ev)
{	
	ev.stopPropagation();
}

function rInputs()
{
	for (i = 0; i < inputs.length; i++)
	{	
		if (inputs[i].type == 'radio')
		{
		    inputs[i].className = 'transparent';
		    rRadios(i);
		}
		else if (inputs[i].type == 'checkbox')
		{
		    inputs[i].className = 'transparent';
		    rCheckboxes(i);
		}
		 
	}
}

function rTextareas()
{
	for (i = 0; i < textareas.length; i++){
		if (textareas[i].getAttribute('rel') == 'customstyle')
		{
			textareas[i].className = 'tag_textarea';	
			textareas[i].onblur = function()
			{
				this.className = 'tag_textarea';
			}
			textareas[i].onfocus = function()
			{
				this.className = 'tag_textarea_focus';
			}
			textareas[i].onmouseover = function()
			{	
				if (this.className != 'tag_textarea_focus')
				{
					this.className = 'tag_textarea_hover';
				}
			}
			textareas[i].onmouseout = function()
			{	
				if (this.className != 'tag_textarea_focus')
				{
					this.className = 'tag_textarea';
				}
			}
		}
	}
}

function rSubmits(i)
{
	inputs[i].className = 'type_submit';
	inputs[i].onmouseover = function()
	{
		this.className='type_submit_hover';
	}
	inputs[i].onmouseout =  function()
	{
		this.className='type_submit';
	}
}

function rTextPassword(i)
{
	inputs[i].className = 'type_text';	
	inputs[i].onblur = function()
	{
		this.className = 'type_text';
	}
	inputs[i].onfocus = function()
	{
		this.className = 'type_text_focus';
	}
	inputs[i].onmouseover = function()
	{	
		if (this.className != 'type_text_focus')
		{
			this.className = 'type_text_hover';
		}
	}
	inputs[i].onmouseout =  function()
	{	
		if (this.className != 'type_text_focus')
		{
			this.className = 'type_text';
		}
	}
}

function rRadios(i)
{
	radio_type = document.createElement('div');
		radio_type.id = 'radio_' + inputs[i].name + '_' + inputs[i].id;
		radio_type.className = 'type_radio';
		if (inputs[i].checked)
		{
			radio_type.className = 'type_radio_checked';
		}
		radio_type.style.cursor = 'pointer';
		radio_type.style.position = 'absolute';
		radio_type.style.display = 'block';
		radio_type.style.zIndex = '998';

		// fixed by liuran 2009-4-25 扩展显示内容。
		for (n = 0; n < labels.length; n++){
			if (labels[n].getAttribute('for') == inputs[i].id )
			{
				radio_type.innerHTML = labels[n].innerHTML;
				labels[n].style.display = 'none';
				break;
			}			
		}

	inputs[i].parentNode.insertBefore(radio_type, inputs[i]);	

	radio_type.onmouseover = new Function("mouseOverRadios('" + radio_type.id + "')");
	radio_type.onmouseout = new Function("mouseOutRadios('" + radio_type.id + "')");
	radio_type.onclick = new Function("clickRadios(" + i + ",'" + inputs[i].name + "','" + inputs[i].id + "')");

}

function rCheckboxes(i)
{
	checkbox_type = document.createElement('div');
		checkbox_type.id = 'checkbox_' + inputs[i].name + '_' + inputs[i].id;
		checkbox_type.className = 'type_checkbox';
		if (inputs[i].checked)
		{
			checkbox_type.className = 'type_checkbox_checked';
		}
		checkbox_type.style.cursor = 'pointer';
		checkbox_type.style.position = 'absolute';
		checkbox_type.style.display = 'block';
		checkbox_type.style.zIndex = '998';

		// fixed by liuran 2009-4-25 扩展显示内容。
		for (n = 0; n < labels.length; n++){
			if (labels[n].getAttribute('for') == inputs[i].id )
			{
				checkbox_type.innerHTML = labels[n].innerHTML;
				labels[n].style.display = 'none';
				break;
			}			
		}


	inputs[i].parentNode.insertBefore(checkbox_type,inputs[i]);
	
	checkbox_type.onmouseover = new Function("mouseOverCheckboxes('" + checkbox_type.id + "')");
	checkbox_type.onmouseout = new Function("mouseOutCheckboxes('" + checkbox_type.id + "')");
	checkbox_type.onclick = new Function("clickCheckboxes(" + i + ",'" + inputs[i].name + "','" + inputs[i].id + "')");
}

function mouseOverRadios(id){
	if (dom(id).className == 'type_radio')
	{
		dom(id).className = 'type_radio_hover';
	}
	else if (dom(id).className == 'type_radio_checked')
	{
		dom(id).className = 'type_radio_checked_hover';
	}
}

function mouseOutRadios(id){
	if (dom(id).className == 'type_radio_hover')
	{
		dom(id).className = 'type_radio';
	}
	else if (dom(id).className == 'type_radio_checked_hover')
	{
		dom(id).className = 'type_radio_checked';
	}
}

function mouseOverCheckboxes(id)
{
	if (dom(id).className == 'type_checkbox')
	{
		dom(id).className = 'type_checkbox_hover';
	}
	else if (dom(id).className == 'type_checkbox_checked')
	{
		dom(id).className = 'type_checkbox_checked_hover';
	}
}

function mouseOutCheckboxes(id)
{
	if (dom(id).className == 'type_checkbox_hover')
	{
		dom(id).className = 'type_checkbox';
	}
	else if (dom(id).className == 'type_checkbox_checked_hover')
	{
		dom(id).className = 'type_checkbox_checked';
	}
}

function clickRadios(i, name, id)
{
	radioid = 'radio_' + name + '_' + id ;
	for (n = 0; n < inputs.length; n++)
	{	
		if (inputs[n].type == 'radio')
		{			
			if (inputs[n].name == name)
			{
				dom('radio_' + inputs[n].name + '_' + inputs[n].id).className = 'type_radio' ;
			}
		}
	}
	if (dom(radioid).className == 'type_radio')
	{
		dom(radioid).className = 'type_radio_checked_hover';
	}	
	inputs[i].click();
}


function clickCheckboxes(i, name, id)
{
	inputs[i].click();
	checkboxid = 'checkbox_' + name + '_' + id;
	var check = dom(checkboxid) ;
	
	if (check.className == 'type_checkbox_hover')
	{
		check.className = 'type_checkbox_checked_hover';
	}
	else if (check.className == 'type_checkbox_checked_hover')
	{
		check.className = 'type_checkbox_hover';		
	}

}

function clickLabelsSelect(name)
{	
	var selectid = 'select_info_' + name;
	var optionul = 'options_' + name;
 
	if (dom(selectid).className == 'tag_select')
	{
		dom(selectid).className = 'tag_select_open';
		dom(optionul).style.display = 'block';
	}
	
}


function rSelects()
{
	for (i = 0; i < selects.length; i++)
	{
		if (selects[i].getAttribute('rel') == 'customstyle')
		{			
			pos = getElementPos( selects[i] );
			
			selects[i].style.display = 'none';
			select_tag = document.createElement('div');
			select_tag.id = 'select_' + selects[i].name;
			select_tag.className = 'select_box';
			selects[i].parentNode.insertBefore(select_tag, selects[i]);
			select_info = document.createElement('div');	
				select_info.id = 'select_info_' + selects[i].name;
				select_info.className = 'tag_select';
				select_info.style.cursor = 'pointer';
			select_tag.appendChild(select_info);
			
			select_ul = document.createElement('ul');	
			select_ul.id = 'options_' + selects[i].name;
			select_ul.className = 'tag_options';
			select_ul.style.position = 'absolute';
			select_ul.style.display = 'none';
			select_ul.style.zIndex = '999';
			
			select_ul.style.top  = pos.y  + 'px';
			select_ul.style.left = pos.x + 'px';

			select_tag.appendChild(select_ul);
			rOptions(i, selects[i].name);		
			mouseSelects(selects[i].name);
			
			if (isIE)
			{			
				selects[i].onclick = Function("clickLabelsSelect('" + selects[i].name + "'); window.event.cancelBubble = true;");
			}
			else if (!isIE)
			{
				selects[i].onclick = new Function("clickLabelsSelect('" + selects[i].name + "')");
				selects[i].addEventListener("click", stopBubbling, false);
			}
		}
	}
}


function rOptions(i, name)
{
	var options = selects[i].getElementsByTagName('option');
	var options_ul = 'options_' + name;
	dom(options_ul).innerHTML ='';
	
	for (n=0;n<selects[i].options.length;n++)
	{	
		option_li = document.createElement('li');
			option_li.style.cursor = 'pointer';
			option_li.className = 'open';

		dom(options_ul).appendChild(option_li);
		option_text = document.createTextNode(selects[i].options[n].text);
		option_li.appendChild(option_text);
		option_selected = selects[i].options[n].selected;

		if (option_selected)
		{
			option_li.className = 'open_selected';
			option_li.id = 'selected_' + name;
			dom('select_info_' + name).innerHTML = '';
			dom('select_info_' + name).appendChild(document.createTextNode(option_li.innerHTML));
		}		
		option_li.onmouseover = function()
		{
			this.className = 'open_hover';
		}
		option_li.onmouseout = function()
		{
			if (this.id == 'selected_' + name)
			{
				this.className = 'open_selected';
			}
			else
			{
				this.className = 'open';
			}
		} 
	
		option_li.onclick = new Function("clickOptions(" + i + "," + n + ",'" + selects[i].name + "')");
	}
}

function mouseSelects(name)
{
	var sincn = 'select_info_' + name;
	dom(sincn).onmouseover = function()
	{
		if (this.className == 'tag_select') this.className = 'tag_select_hover';
	}
	dom(sincn).onmouseout = function()
	{
		if (this.className == 'tag_select_hover') this.className = 'tag_select';
	}
	if (isIE)
	{
		dom(sincn).onclick = new Function("clickSelects('" + name + "');window.event.cancelBubble = true;");
	}
	else if (!isIE)
	{
		dom(sincn).onclick = new Function("clickSelects('" + name + "');");
		dom('select_info_' + name).addEventListener("click", stopBubbling, false);
	}

}

function clickSelects(name)
{
	var sincn = 'select_info_' + name;
	var sinul = 'options_' + name;	

	for (i=0;i<selects.length;i++)
	{	
		if (selects[i].getAttribute('rel') == 'customstyle')
		{
			if (selects[i].name == name)
			{				
				if ( dom(sincn).className == 'tag_select_hover')
				{
					dom(sincn).className = 'tag_select_open';
					dom(sinul).style.display = '';
				}
				else if ( dom(sincn).className == 'tag_select_open')
				{
					dom(sincn).className = 'tag_select_hover';
					dom(sinul).style.display = 'none';
				}
			}
			else
			{ 	dom('select_info_' + selects[i].name).className = 'tag_select';
				dom('options_' + selects[i].name).style.display = 'none';
			}
		}
	}

}

function clickOptions(i, n, name)
{		
	var li = dom('options_' + name).getElementsByTagName('li');
	dom('selected_' + name).className = 'open';
	dom('selected_' + name).id = '';
	li[n].id = 'selected_' + name;
	li[n].className = 'open_hover';
	dom('select_' + name).removeChild(dom('select_info_' + name));
	select_info = document.createElement('div');
		select_info.id = 'select_info_' + name;
		select_info.className = 'tag_select';
		select_info.style.cursor = 'pointer';
	dom('options_' + name).parentNode.insertBefore(select_info,dom('options_' + name));
	mouseSelects(name);
	dom('select_info_' + name).innerHTML = '';
	dom('select_info_' + name).appendChild(document.createTextNode(li[n].innerHTML));
	dom( 'options_' + name ).style.display = 'none' ;
	dom( 'select_info_' + name ).className = 'tag_select';
	selects[i].options[n].selected = 'selected';
	if (selects[i].onchange)
	{
		selects[i].onchange();
	}
  
}


function checkInputs()
{
	for (i = 0; i < inputs.length; i++)
	{	
		if (inputs[i].type == 'checkbox')
		{
			checkboxid = 'checkbox_' + inputs[i].name + '_' + inputs[i].id;
			
			if (inputs[i].checked == true)
			{
				if (dom(checkboxid).className == 'type_checkbox_hover')
				{
					dom(checkboxid).className = 'type_checkbox_checked_hover';
				}
				else
				{
					dom(checkboxid).className = 'type_checkbox_checked';
				}
			}
			else if (inputs[i].checked == false)
			{
				if (dom(checkboxid).className == 'type_checkbox_checked_hover')
				{
					dom(checkboxid).className = 'type_checkbox_hover';
				}
				else
				{
					dom(checkboxid).className = 'type_checkbox';
				}
			}
		}
		else if (inputs[i].type == 'radio')
		{
			radioid = 'radio_' + inputs[i].name + '_' + inputs[i].id;
			
			if (inputs[i].checked == true)
			{
				if (dom(radioid).className == 'type_radio_hover')
				{
					dom(radioid).className = 'type_radio_checked_hover';
				}
				else if (dom(radioid).className == 'type_radio_checked_hover')
				{
					// Nothing to do.
				}
				else
				{
					dom(radioid).className = 'type_radio_checked';
				}
			}
			else if (inputs[i].checked == false)
			{
				dom(radioid).className = 'type_radio';
			}
		}
	}
}


function checkAllCheckboxs(form, prefix, stats)
{	
	for (var i = 0; i < form.elements.length; i++)
	{
		var e = form.elements[i];
		
		if (e.name && e.type == 'checkbox' && (!prefix || (prefix && e.name.match(prefix))))
		{
			e.checked = stats;
		}
	}
}
 


window.addEvent('load',function(){
								
	$("topMenu").getElements('div').addEvents({
		'mouseover':function(){
			rollmove(this, 1);
			},
		'mouseout': function(){
			rollmove(this, 0);
			}
	});	
	
	// 修改自定义样式	
	inputs = findCustomeTags('input');
	textareas = findCustomeTags('textarea');
	selects = findCustomeTags('select');

	bodyclick = document.getElementsByTagName('body').item(0);
	rSelects();
	bodyclick.onclick = function()
	{
		for (i = 0; i < selects.length; i++)
		{	
			dom('select_info_' + selects[i].name).className = 'tag_select';
			dom('options_' + selects[i].name).style.display = 'none';
		}		
		checkInputs();
	}
});

function findCustomeTags( tagname ){
	var allTags = document.getElementsByTagName(tagname);
	var founded = new Array();
	
	for(i=0; i< allTags.length; i++){
			
		if (allTags[i].getAttribute('rel') == 'customstyle'){
			founded.push(allTags[i]);
		}
	}
	return founded;
}



function jumpto(url, id)
{
	var urlstr = url + id;
	window.open(urlstr);
	return false;
}